﻿
dynamic class DataProvider
{
	private var _dataname:String;
	private var _so:SharedObject;
	
	public function get SO():SharedObject
	{
		return _so;
	}
	public function get DataName():String
	{
		return _dataname;
	}
	public function set DataName(value:String)
	{
		if (value == null)
		{
			_so = null;
			_dataname = value;
		}else
		{
			_dataname = value;
			_so = SharedObject.getLocal(value);
			checkSO();
		}
	}
	public function DataProvider(name:String)
	{
		if (name == "" || name == undefined)
		{
			name = "defaultSO";
		}
		_dataname = name;
		_so = SharedObject.getLocal(name);
	}
	public function getDatas(fieldsToFull:Object):Object
	{
		if (!checkSO())
		{
			return null;
		}
		var newObej:Object = new Object();
		for (var i:String in fieldsToFull)
		{
			newObej[i] = _so.data[i];
		}
		return newObej;
	}
	public function setDatas(datas:Object):Boolean
	{
		if (!checkSO())
		{
			return false;
		}
		for (var i:String in datas)
		{
			_so.data[i] = datas[i];
		}
		return true;
	}
	private function checkSO():Boolean
	{
		if (_so == null)
		{
			trace("由于安全，或其它问题，不能获取存取空间。");
			return false;
		}
		return true;
	}
}